package com.hxd.otc.module.wallet.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.wallet.bean.WalletCurrencyBean;
import com.hxd.otc.module.wallet.contract.AddWalletContactContract;
import com.hxd.otc.module.wallet.model.WalletModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

import java.util.List;

/**
 * Created by lzy on 2018/8/6 0006.
 * description ${添加钱包联系人 Presenter}
 */
public class AddWalletContactPresenter extends BasePresenter<AddWalletContactContract.View> implements AddWalletContactContract.Presenter {

    private final WalletModel mModel;
    List<WalletCurrencyBean> walletInfoBeans;
    public AddWalletContactPresenter(AddWalletContactContract.View view) {
        super(view);
        mModel = WalletModel.getInstance();
    }

    @Override
    public void start() {

    }


    @Override
    public void addWalletContact(String... paramters) {
        mView.onShowLoading();
        mModel.addWalletContact(new BaseObserver<BaseBean>() {
            @Override
            public void onNext(String title, BaseBean bean) {
                mView.onHideLoading();
                mView.addWalletContractSuccess();
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.onHideLoading();
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean>bindAutoDispose(), paramters);
    }

    @Override
    public void getCoinType() {
        mModel.getWalletAccountInfo(new BaseObserver<List<WalletCurrencyBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull List<WalletCurrencyBean> walletCurrencyBeans) {
               setWalletInfoBeans(walletCurrencyBeans);
                mView.coinTypeSuccess();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {

                mView.showToast(errMessage);
            }


        }, mView.<BaseBean<List<WalletCurrencyBean>>>bindAutoDispose(), true);
    }

    public void setWalletInfoBeans(List<WalletCurrencyBean> walletInfoBeans) {
        this.walletInfoBeans = walletInfoBeans;
    }

    public List<WalletCurrencyBean> getWalletInfoBeans() {
        return walletInfoBeans;
    }
}
